package com.euq.mapper;

import com.euq.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    @Select("select * from user")
    List<User> listAll();
    @Select("select * from user where roleId=#{rouleId}")
    User findByRoleId(String roleId);
    @Select({
            "<script>",
            "SELECT * FROM user",
            "<where>",
            "  <if test='account != null and account != \"\"'>",
            "    AND account = #{account}",
            "  </if>",
            "  <if test='status != null and status != \"\"'>",
            "    AND status = #{status}",
            "  </if>",
            "  <if test='name != null and name != \"\"'>",
            "    AND name LIKE CONCAT('%', #{name}, '%')",
            "  </if>",
            "</where>",
            "</script>"
    })
    List<User> selectByConditions(@Param("account") String account,
                                  @Param("status") String status,
                                  @Param("name") String name);
    @Select("select * from user where account = #{account}")
    User findByAccount(String account);
    @Select("select * from user where id = #{id}")
    User findById(Long id);
    @Insert({
            "insert into user (create_by, create_time, modify_by, modify_time, account, avatar, birthday, deptId, email, name, password, phone, roleId, salt, sex, status, version)",
            "values (1,now(),1,now(),#{account},#{avatar},#{birthday},#{deptId},#{email},#{name},#{password},#{phone},#{roleId},#{salt},#{sex},#{status},#{version})"
    })
    void insert(User user);
    @Update({
            "update user",
            "set create_by=1,",
            "create_time=now(),",
            "modify_by=1,",
            "modify_time=now(),",
            "account=#{account},",
            "avatar=#{avatar},",
            "birthday=#{birthday},",
            "deptId=#{deptId},",
            "email=#{email},",
            "name=#{name},",
            "password=#{password},",
            "phone=#{phone},",
            "roleId=#{roleId},",
            "salt=#{salt},",
            "sex=#{sex},",
            "status=#{status},",
            "version=#{version}",
            "where id=#{id}"
    })
    void update(User user);
}
